package com.lazy.app.presenter;

import com.lazy.app.ui.act.H5Activity;
import com.zndroid.base.ui.impl.BasePresenter;

/**
 * @author lzy
 */
public class H5Presenter extends BasePresenter<H5Activity> {
    public static final String NAME_SPACE = "app";

    public static final String H5_KEY_URL = "url";
    public static final String H5_KEY_TYPE = "type";
    public static final String H5_KEY_USE_NATIVE_TITLE = "is_android_title";
    public static final String H5_KEY_TITLE = "title";

    public static final int H5_TYPE_OF_USER_AGREEMENT = 0x000000;
    public static final int H5_TYPE_OF_PRIVACY_POLICY = 0x000001;
    public static final int H5_TYPE_OF_OFFICE_WEB_SIT = 0x000002;

    /**错误页面*/
    private final static String H5_URL_ERROR_PAGE = "file:///android_asset/static/h5/bridge_error/index.html";
    /**用户协议*/
    public static final String H5_URL_OF_USER_AGREEMENT = "file:///android_asset/static/h5/user_agreement.html";
    /**隐私政策*/
    public static final String H5_URL_OF_PRIVACY_POLICY = "file:///android_asset/static/h5/privacy_policy.html";
    /**应用权限*/
    public static final String H5_URL_OF_APPLICATION_PERMISSIONS = "file:///android_asset/static/h5/application_permissions.html";
    /**第三方SDK说明*/
    public static final String H5_URL_OF_EXPLAIN_SDK_3RD = "file:///android_asset/static/h5/explain_sdk_3rd.html";

    public static final String H5_URL_OF_OFFICE_WEB_SIT = "https://gitee.com/zndroidx";

    private int type = -1;
    private String url;

    /**H5地址*/
    public String getUrl() {
        return url;
    }

    /**页面业务逻辑类型*/
    public int getType() {
        return type;
    }

    @Override
    public void didOnCreate() {
        super.didOnCreate();

        String title = "";
        String url = H5_URL_ERROR_PAGE;
        boolean useAndroidTitle = false;
        int type = -1;

        if (null != getV().getBundleArgs()) {
            title = getBundleArgs().getString(H5_KEY_TITLE, "");
            url = getBundleArgs().getString(H5_KEY_URL, H5_URL_ERROR_PAGE);
            useAndroidTitle = getBundleArgs().getBoolean(H5_KEY_USE_NATIVE_TITLE, false);
            type = getBundleArgs().getInt(H5_KEY_TYPE, -1);
        }

        this.url = url;
        this.type = type;

        getV().updateTitle(useAndroidTitle, title);
        getV().loadH5();
    }
}
